home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Tools / Turbo Pascal V7 / INTRFACE.ZIP / OBJECTS.INT < prev    next >
Text File  |  1992-11-03  |  10KB  |  384 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Version 7.0                        }
  5. {       Standard Objects Unit                           }
  6. {                                                       }
  7. {       Copyright (c) 1991,92 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit Objects;
  12.  
  13. {$O+,F+,X+,I-,S-}
  14.  
  15. interface
  16.  
  17. const
  18.  
  19. { TStream access modes }
  20.  
  21.   stCreate    = $3C00;           { Create new file }
  22.   stOpenRead  = $3D00;           { Read access only }
  23.   stOpenWrite = $3D01;           { Write access only }
  24.   stOpen      = $3D02;           { Read and write access }
  25.  
  26. { TStream error codes }
  27.  
  28.   stOk         =  0;              { No error }
  29.   stError      = -1;              { Access error }
  30.   stInitError  = -2;              { Cannot initialize stream }
  31.   stReadError  = -3;              { Read beyond end of stream }
  32.   stWriteError = -4;              { Cannot expand stream }
  33.   stGetError   = -5;              { Get of unregistered object type }
  34.   stPutError   = -6;              { Put of unregistered object type }
  35.  
  36. { Maximum TCollection size }
  37.  
  38.   MaxCollectionSize = 65520 div SizeOf(Pointer);
  39.  
  40. { TCollection error codes }
  41.  
  42.   coIndexError = -1;              { Index out of range }
  43.   coOverflow   = -2;              { Overflow }
  44.  
  45. { VMT header size }
  46.  
  47.   vmtHeaderSize = 8;
  48.  
  49. type
  50.  
  51. { Type conversion records }
  52.  
  53.   WordRec = record
  54.     Lo, Hi: Byte;
  55.   end;
  56.  
  57.   LongRec = record
  58.     Lo, Hi: Word;
  59.   end;
  60.  
  61.   PtrRec = record
  62.     Ofs, Seg: Word;
  63.   end;
  64.  
  65. { String pointers }
  66.  
  67.   PString = ^String;
  68.  
  69. { Character set type }
  70.  
  71.   PCharSet = ^TCharSet;
  72.   TCharSet = set of Char;
  73.  
  74. { General arrays }
  75.  
  76.   PByteArray = ^TByteArray;
  77.   TByteArray = array[0..32767] of Byte;
  78.  
  79.   PWordArray = ^TWordArray;
  80.   TWordArray = array[0..16383] of Word;
  81.  
  82. { TObject base object }
  83.  
  84.   PObject = ^TObject;
  85.   TObject = object
  86.     constructor Init;
  87.     procedure Free;
  88.     destructor Done; virtual;
  89.   end;
  90.  
  91. { TStreamRec }
  92.  
  93.   PStreamRec = ^TStreamRec;
  94.   TStreamRec = record
  95.     ObjType: Word;
  96.     VmtLink: Word;
  97.     Load: Pointer;
  98.     Store: Pointer;
  99.     Next: Word;
  100.   end;
  101.  
  102. { TStream }
  103.  
  104.   PStream = ^TStream;
  105.   TStream = object(TObject)
  106.     Status: Integer;
  107.     ErrorInfo: Integer;
  108.     procedure CopyFrom(var S: TStream; Count: Longint);
  109.     procedure Error(Code, Info: Integer); virtual;
  110.     procedure Flush; virtual;
  111.     function Get: PObject;
  112.     function GetPos: Longint; virtual;
  113.     function GetSize: Longint; virtual;
  114.     procedure Put(P: PObject);
  115.     procedure Read(var Buf; Count: Word); virtual;
  116.     function ReadStr: PString;
  117.     procedure Reset;
  118.     procedure Seek(Pos: Longint); virtual;
  119.     procedure Truncate; virtual;
  120.     procedure Write(var Buf; Count: Word); virtual;
  121.     procedure WriteStr(P: PString);
  122.   end;
  123.  
  124. { DOS file name string }
  125.  
  126.   FNameStr = string[79];
  127.  
  128. { TDosStream }
  129.  
  130.   PDosStream = ^TDosStream;
  131.   TDosStream = object(TStream)
  132.     Handle: Word;
  133.     constructor Init(FileName: FNameStr; Mode: Word);
  134.     destructor Done; virtual;
  135.     function GetPos: Longint; virtual;
  136.     function GetSize: Longint; virtual;
  137.     procedure Read(var Buf; Count: Word); virtual;
  138.     procedure Seek(Pos: Longint); virtual;
  139.     procedure Truncate; virtual;
  140.     procedure Write(var Buf; Count: Word); virtual;
  141.   end;
  142.  
  143. { TBufStream }
  144.  
  145.   PBufStream = ^TBufStream;
  146.   TBufStream = object(TDosStream)
  147.     Buffer: Pointer;
  148.     BufSize: Word;
  149.     BufPtr: Word;
  150.     BufEnd: Word;
  151.     constructor Init(FileName: FNameStr; Mode, Size: Word);
  152.     destructor Done; virtual;
  153.     procedure Flush; virtual;
  154.     function GetPos: Longint; virtual;
  155.     function GetSize: Longint; virtual;
  156.     procedure Read(var Buf; Count: Word); virtual;
  157.     procedure Seek(Pos: Longint); virtual;
  158.     procedure Truncate; virtual;
  159.     procedure Write(var Buf; Count: Word); virtual;
  160.   end;
  161.  
  162. { TEmsStream }
  163.  
  164.   PEmsStream = ^TEmsStream;
  165.   TEmsStream = object(TStream)
  166.     Handle: Word;
  167.     PageCount: Word;
  168.     Size: Longint;
  169.     Position: Longint;
  170.     constructor Init(MinSize, MaxSize: Longint);
  171.     destructor Done; virtual;
  172.     function GetPos: Longint; virtual;
  173.     function GetSize: Longint; virtual;
  174.     procedure Read(var Buf; Count: Word); virtual;
  175.     procedure Seek(Pos: Longint); virtual;
  176.     procedure Truncate; virtual;
  177.     procedure Write(var Buf; Count: Word); virtual;
  178.   end;
  179.  
  180. { TCollection types }
  181.  
  182.   PItemList = ^TItemList;
  183.   TItemList = array[0..MaxCollectionSize - 1] of Pointer;
  184.  
  185. { TCollection object }
  186.  
  187.   PCollection = ^TCollection;
  188.   TCollection = object(TObject)
  189.     Items: PItemList;
  190.     Count: Integer;
  191.     Limit: Integer;
  192.     Delta: Integer;
  193.     constructor Init(ALimit, ADelta: Integer);
  194.     constructor Load(var S: TStream);
  195.     destructor Done; virtual;
  196.     function At(Index: Integer): Pointer;
  197.     procedure AtDelete(Index: Integer);
  198.     procedure AtFree(Index: Integer);
  199.     procedure AtInsert(Index: Integer; Item: Pointer);
  200.     procedure AtPut(Index: Integer; Item: Pointer);
  201.     procedure Delete(Item: Pointer);
  202.     procedure DeleteAll;
  203.     procedure Error(Code, Info: Integer); virtual;
  204.     function FirstThat(Test: Pointer): Pointer;
  205.     procedure ForEach(Action: Pointer);
  206.     procedure Free(Item: Pointer);
  207.     procedure FreeAll;
  208.     procedure FreeItem(Item: Pointer); virtual;
  209.     function GetItem(var S: TStream): Pointer; virtual;
  210.     function IndexOf(Item: Pointer): Integer; virtual;
  211.     procedure Insert(Item: Pointer); virtual;
  212.     function LastThat(Test: Pointer): Pointer;
  213.     procedure Pack;
  214.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  215.     procedure SetLimit(ALimit: Integer); virtual;
  216.     procedure Store(var S: TStream);
  217.   end;
  218.  
  219. { TSortedCollection object }
  220.  
  221.   PSortedCollection = ^TSortedCollection;
  222.   TSortedCollection = object(TCollection)
  223.     Duplicates: Boolean;
  224.     constructor Load(var S: TStream);
  225.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  226.     function IndexOf(Item: Pointer): Integer; virtual;
  227.     procedure Insert(Item: Pointer); virtual;
  228.     function KeyOf(Item: Pointer): Pointer; virtual;
  229.     function Search(Key: Pointer; var Index: Integer): Boolean; virtual;
  230.     procedure Store(var S: TStream);
  231.   end;
  232.  
  233. { TStringCollection object }
  234.  
  235.   PStringCollection = ^TStringCollection;
  236.   TStringCollection = object(TSortedCollection)
  237.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  238.     procedure FreeItem(Item: Pointer); virtual;
  239.     function GetItem(var S: TStream): Pointer; virtual;
  240.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  241.   end;
  242.  
  243. { TResourceCollection object }
  244.  
  245.   PResourceCollection = ^TResourceCollection;
  246.   TResourceCollection = object(TStringCollection)
  247.     procedure FreeItem(Item: Pointer); virtual;
  248.     function GetItem(var S: TStream): Pointer; virtual;
  249.     function KeyOf(Item: Pointer): Pointer; virtual;
  250.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  251.   end;
  252.  
  253. { TResourceFile object }
  254.  
  255.   PResourceFile = ^TResourceFile;
  256.   TResourceFile = object(TObject)
  257.     Stream: PStream;
  258.     Modified: Boolean;
  259.     constructor Init(AStream: PStream);
  260.     destructor Done; virtual;
  261.     function Count: Integer;
  262.     procedure Delete(Key: String);
  263.     procedure Flush;
  264.     function Get(Key: String): PObject;
  265.     function KeyAt(I: Integer): String;
  266.     procedure Put(Item: PObject; Key: String);
  267.     function SwitchTo(AStream: PStream; Pack: Boolean): PStream;
  268.   end;
  269.  
  270. { TStringList object }
  271.  
  272.   TStrIndexRec = record
  273.     Key, Count, Offset: Word;
  274.   end;
  275.  
  276.   PStrIndex = ^TStrIndex;
  277.   TStrIndex = array[0..9999] of TStrIndexRec;
  278.  
  279.   PStringList = ^TStringList;
  280.   TStringList = object(TObject)
  281.     constructor Load(var S: TStream);
  282.     destructor Done; virtual;
  283.     function Get(Key: Word): String;
  284.   end;
  285.  
  286. { TStrListMaker object }
  287.  
  288.   PStrListMaker = ^TStrListMaker;
  289.   TStrListMaker = object(TObject)
  290.     constructor Init(AStrSize, AIndexSize: Word);
  291.     destructor Done; virtual;
  292.     procedure Put(Key: Word; S: String);
  293.     procedure Store(var S: TStream);
  294.   end;
  295.  
  296. { TPoint object }
  297.  
  298.   TPoint = object
  299.     X, Y: Integer;
  300.   end;
  301.  
  302. { Rectangle object }
  303.  
  304.   TRect = object
  305.     A, B: TPoint;
  306.     procedure Assign(XA, YA, XB, YB: Integer);
  307.     procedure Copy(R: TRect);
  308.     procedure Move(ADX, ADY: Integer);
  309.     procedure Grow(ADX, ADY: Integer);
  310.     procedure Intersect(R: TRect);
  311.     procedure Union(R: TRect);
  312.     function Contains(P: TPoint): Boolean;
  313.     function Equals(R: TRect): Boolean;
  314.     function Empty: Boolean;
  315.   end;
  316.  
  317. { Dynamic string handling routines }
  318.  
  319. function NewStr(const S: String): PString;
  320. procedure DisposeStr(P: PString);
  321.  
  322. { Longint routines }
  323.  
  324. function LongMul(X, Y: Integer): Longint;
  325. inline($5A/$58/$F7/$EA);
  326.  
  327. function LongDiv(X: Longint; Y: Integer): Integer;
  328. inline($59/$58/$5A/$F7/$F9);
  329.  
  330. { Stream routines }
  331.  
  332. procedure RegisterType(var S: TStreamRec);
  333.  
  334. { Abstract notification procedure }
  335.  
  336. procedure Abstract;
  337.  
  338. { Objects registration procedure }
  339.  
  340. procedure RegisterObjects;
  341.  
  342. const
  343.  
  344. { Stream error procedure }
  345.  
  346.   StreamError: Pointer = nil;
  347.  
  348. { EMS stream state variables }
  349.  
  350.   EmsCurHandle: Word = $FFFF;
  351.   EmsCurPage: Word = $FFFF;
  352.  
  353. { Stream registration records }
  354.  
  355. const
  356.   RCollection: TStreamRec = (
  357.     ObjType: 50;
  358.     VmtLink: Ofs(TypeOf(TCollection)^);
  359.     Load: @TCollection.Load;
  360.     Store: @TCollection.Store);
  361.  
  362. const
  363.   RStringCollection: TStreamRec = (
  364.     ObjType: 51;
  365.     VmtLink: Ofs(TypeOf(TStringCollection)^);
  366.     Load: @TStringCollection.Load;
  367.     Store: @TStringCollection.Store);
  368.  
  369. const
  370.   RStringList: TStreamRec = (
  371.     ObjType: 52;
  372.     VmtLink: Ofs(TypeOf(TStringList)^);
  373.     Load: @TStringList.Load;
  374.     Store: nil);
  375.  
  376. const
  377.   RStrListMaker: TStreamRec = (
  378.     ObjType: 52;
  379.     VmtLink: Ofs(TypeOf(TStrListMaker)^);
  380.     Load: nil;
  381.     Store: @TStrListMaker.Store);
  382.  
  383.  
  384.